<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>删除原始打卡时间</title>
</head>
<body>

<table id="removeOriginalTime_table" class="easyui-datagrid" rownumbers="true" idField="pkImportdata"
       toolbar="#removeOriginalTime_toolbar" pagination="true" style="width:100%;height:100%"
       data-options="pageSize: 50,pageList: [50,100,200]"/>

<div id="removeOriginalTime_toolbar" style="height:100px">
    <div id="removeOriginalTime_panel" class="easyui-panel"
         style="width:1650px;height:100%;background:#fafafa;">
        <form id="removeOriginalTime_form" name="removeOriginalTime_form">
            <div style="float: left">
                <div style="margin: 10px">
                    <input class="easyui-combobox" id="pk_Org" name="pk_Org"
                           data-options="valueField:'pkhrorg',textField:'name',url:'/user/getUserOrgHrorg',label:'组织',labelWidth:'40',required :'required',prompt:'查询必选项'"
                           style="width:260px;"/>
                    <!--根据部门显示员工姓名       <input id="pk_Name" name="pk_Name" style="margin-left: 3px" class="easyui-combobox"-->
                    <!--                           data-options="label:'员工姓名',labelWidth:'60',valueField:'id',textField:'text'"-->
                    <!--                           value="">-->
                    <input name="start_Time" id="start_Time" data-options="label:'刷卡日期',labelWidth:'60',prompt:'查询必选项'"
                           style="width:230px" class="easyui-datebox" editable="false" required="required"/>
                    —
                    <input name="end_Time" id="end_Time" class="easyui-datebox" editable="false" data-options="required :'required',prompt:'查询必选项'"/>
                </div>
                <div style="margin: 10px">
                    <input id="pk_DeptV" name="pk_DeptV" class="easyui-combotree"
                           style="width:260px"
                           data-options="label:'部门',labelWidth:'40',multiple:true,prompt:'请先选择组织'"/>
                    <input class="easyui-textbox" id="pk_Name" name="pk_Name"
                           data-options="label:'员工姓名',labelWidth:'60',prompt:'请输入姓名'">
                    <input id="pk_Code" name="pk_Code" class="easyui-textbox" max="1000000"
                           data-options="label:'员工编码',labelWidth:'60',prompt:'请输入工号'">
                    <input id="Tname" name="Tname" type="text" style="display: none">
                </div>
            </div>
            <div style="margin-top: 8px;float: left">
                <a id="btn" href="#" style="margin-left: 20px;width:120px;height: 50px" class="easyui-linkbutton"
                   data-options="iconCls:'icon-search'" onclick="removeOriginalTimeCheck()">查询</a>
                <a id="delect" href="#" style="margin-left: 20px;width:120px;height: 50px" class="easyui-linkbutton"
                   data-options="iconCls:'icon-remove'" onclick="removeOriginalTimeCheckDelect()">删除</a>
            </div>
        </form>
    </div>
</div>
<script th:inline="none" type="text/javascript">
    //数组去重
    function unique(arr) {
        for (var i = 0; i < arr.length; i++) {
            for (var j = i + 1; j < arr.length; j++) {
                if (arr[i] == arr[j]) {         //第一个等同于第二个，splice方法删除第二个
                    arr.splice(j, 1);
                    j--;
                }
            }
        }
        return arr;
    }

    function removeOriginalTimeCheckDelect() {
        var pkImportdataId = [];
        var Tname = [];
        var rows = $('#removeOriginalTime_table').datagrid('getSelections');
        for (var i = 0; i < rows.length; i++) {
            pkImportdataId.push(rows[i].pkImportdata);
            Tname.push(rows[i].name);
        }
        $('#Tname').val(unique(Tname).join(','));
        if (pkImportdataId.length > 0) {
            $.messager.confirm('确认', '您确认想要删除所选信息吗？', function (r) {
                if (r) {
                    $("#delect").css("color", "#CCC");
                    $('#delect').linkbutton('disable');
                    // 遮罩
                    $("<div class=\"datagrid-mask\"></div>").css({
                        display: "block",
                        width: "100%",
                        height: "auto"
                    }).appendTo("body");
                    $("<div class=\"datagrid-mask-msg\"></div>").html("<img  class ='img1' /> 正在删除数据，请稍候。。。").appendTo("body").css({
                        display: "block",
                        'font-size': '12px',
                        height: "auto",
                        left: ($(document.body).outerWidth(true)) / 2,
                        top: ($(window).height() - 45) / 2
                    });
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "/hr/delectClockInInfo",
                        data: {
                            pkImportdataId: pkImportdataId,
                            name: $('#Tname').val()
                        },
                        success: function (data) {
                            $(".datagrid-mask").remove();//解除遮罩
                            $(".datagrid-mask-msg").remove();
                            $("#delect").linkbutton("enable");
                            $("#delect").css("color", "black");
                            topCommonMessage(data.msg);
                            $('#removeOriginalTime_table').datagrid('clearSelections');//取消选择行
                            removeOriginalTimeCheck();
                            if (data.statu==404){
                                warnSessionConfirm()
                            }
                        },
                        error: function () {
                            $('#removeOriginalTime_table').datagrid('clearSelections');
                            $(".datagrid-mask").remove();
                            $(".datagrid-mask-msg").remove();
                        }
                    })
                }
            });
        } else
            topCommonMessage("请选择要删除的信息！")
    }

    function removeOriginalTimeCheck() {
        $('#removeOriginalTime_table').datagrid('load', {
            pkOrg: $('#pk_Org').val(),
            pkPsndoc: $('#pk_Name').val(),
            pkDeptV: $('#pk_DeptV').val(),
            pkCode: $('#pk_Code').val(),
            startTime: $('#start_Time').val(),
            endTime: $('#end_Time').val()
        });
        if ($('#pk_Org').val() != "" && $('#start_Time').val() != "" && $('#end_Time').val() != "") {
            $('#removeOriginalTime_table').datagrid({
                onLoadSuccess: function (data) {
                    if (data == null || data.total == 0) {
                        topCommonMessage("没有相关的数据或数据已封存!")
                    }
                },
                url: '/hr/clockInInfo',
                columns: [[
                    {field: 'pkImportdata', checkbox: 'true'},
                    {field: 'code', title: '人员编码', width: 100, align: 'center'},
                    {field: 'name', title: '人员姓名', width: 150, align: 'center'},
                    {field: 'calendarTime', title: '刷卡时间', width: 200, align: 'center'},
                    {field: 'machineName', title: '打卡机名称', width: 200, align: 'center'},
                ]]
            })
        } else topCommonMessage("请选择必选项(组织、日期范围)！")
    }

    //根据组织查询部门
    $("#pk_Org").combobox({
        onChange: function (newValue, oldValue) {
            $("#pk_DeptV").combotree({
                url: '/signCardSingle/selectOrgDeptByPkHrorg?pkHrorg=' + newValue
            })
        }
    })

    //根据部门查询人员
    // $("#pk_DeptV").combotree({
    //     onCheck: function (node) {
    //
    //         var t = $('#pk_DeptV').combotree('tree');
    //         var nodes = t.tree('getChecked');
    //         console.log(nodes);
    //         console.log(nodes.children);//undefined 和 数组
    //         //console.log(nodes[0].id);//
    //         var pkDepts = [];
    //         for (var i = 0; i < nodes.length; i++) {
    //             pkDepts.push(nodes[i].id);
    //         }
    //         if (pkDepts.length > 0) {
    //             //根据后台获取数据
    //             $.post({
    //                 url: '/signCardSingle/getDeptPsndoc',
    //                 data: {'pkDepts': pkDepts},
    //                 success: function (data) {
    //                     $('#pk_Name').combobox({
    //                         data: data,
    //                         singleSelect: true,
    //                         valueField: 'pk_Name',
    //                         textField: 'name'
    //                     });
    //                 }
    //             })
    //         } else {
    //             $('#pk_Name').combobox({
    //                 data: [],
    //                 valueField: 'pk_Name',
    //                 textField: 'name'
    //             });
    //         }
    //     }
    // })

</script>

</body>
</html>